package com.skyyan.netty.jjf.client.handler;

import com.skyyan.netty.jjf.client.MessageHandler;
import com.skyyan.netty.jjf.protocol.Message;
import com.skyyan.netty.jjf.protocol.RechargeMessage;

/**
 * 充值消息处理器
 */
public class RechargeMessageHandler implements MessageHandler {
    @Override
    public boolean canHandle(Message msg) {
        return msg instanceof RechargeMessage;
    }
    
    @Override
    public void handle(Message msg) {
        if (msg instanceof RechargeMessage.Downlink) {
            RechargeMessage.Downlink downlink = (RechargeMessage.Downlink) msg;
            System.out.println("充值下行报文:");
            System.out.println("  状态码: 0x" + String.format("%02X", downlink.getStatusCodeBCD()));
            System.out.println("  余额: " + downlink.getBalance() + "分");
            System.out.println("  用户名: " + downlink.getUsername());
            System.out.println("  订单号: " + downlink.getOrderNoString());
        } else {
            System.out.println("充值上行报文");
        }
    }
}